var gulp = require('gulp'),
    jade = require('gulp-jade'),
    sass = require('gulp-sass');

var browserSync = require('browser-sync').create();

gulp.task('sass', function() {
    gulp.src('./sass/*.scss')
        .pipe(sass().on('error', sass.logError))
        .pipe(gulp.dest('../app/css'))
        .pipe(browserSync.stream());
});

gulp.task('jade', function() {
    gulp.src(['./jade/*.jade', '!./jade/index.jade'])
        .pipe(jade({ pretty: true }))
        .pipe(gulp.dest('../app/views'))
        .pipe(browserSync.stream());
});

gulp.task('js', function() {
    return gulp.src('./js/**/*.js')
        // .pipe(browserify())
        // .pipe(uglify())
        .pipe(gulp.dest('../app/js'))
        .pipe(browserSync.stream());
});

gulp.task('watch', ['jade', 'sass', 'js'], function() {
    browserSync.init({ server: { baseDir: '../app', index: '/views/login.html' } });
    gulp.watch('./sass/*.scss', ['sass']);
    gulp.watch(['./jade/*.jade', './jade/includes/*.jade'], ['jade']);
    gulp.watch("./js/**/*.js", ['js']);
    gulp.watch('./jade/*.jade').on('change', browserSync.reload);
});

gulp.task('default', ['watch']);
